package com.tanhua.dubbo.db.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.db.mappers.BlackListMapper;
import com.tanhua.dubbo.db.mappers.UserInfoMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;


    @Override
    public PageResult blacklist(Long userId, Integer page, Integer pagesize) {

        //设置分页
        Page pageParam=new Page(page,pagesize);


        IPage<UserInfo> infoIPage = userInfoMapper.findBlackList(pageParam, userId);

        return new PageResult(page,pagesize,infoIPage.getCurrent(),infoIPage.getRecords());
    }

    //黑名单 - 根据blackUserId移除
    @Override
    public void deleteBlackUser(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> qw=new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw);

    }
}
